<template>
  <div>
    <van-nav-bar
      title="更改昵称"
      left-text="取消"
      right-text="保存"
      left-arrow
      @click-left="$parent.$parent.show = false"
      @click-right="getuploadProfile"
    />

    <van-field
      v-model="nickname"
      rows="2"
      autosize
      maxlength="50"
      type="textarea"
      show-word-limit
    />
  </div>
</template>

<script>
import { getuploadProfile } from '@/api'
export default {
  name: 'UpdateName',
  data() {
    return {
      nickname: this.$parent.$parent.UserInfo.name
    }
  },
  mounted() {
    this.getuploadProfile()
  },
  methods: {
    async getuploadProfile() {
      try {
        const data = { name: this.nickname }
        await getuploadProfile(data)
        this.$parent.$parent.getUserInfo()
        this.$parent.$parent.show = false
        this.$toast.success('名称修改成功!')
      } catch (error) {
        this.$toast.fail('名称修改失败!')
      }
    }
  }
}
</script>

<style scoped lang="less"></style>
